package com.ruoyi.staff.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.staff.domain.StaffCheck;
import com.ruoyi.staff.service.IStaffCheckService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工考勤Controller
 * 
 * @author bzs
 * @date 2021-07-05
 */
@Controller
@RequestMapping("/staff/check")
public class StaffCheckController extends BaseController
{
    private String prefix = "staff/check";

    @Autowired
    private IStaffCheckService staffCheckService;

    @RequiresPermissions("staff:check:view")
    @GetMapping()
    public String check()
    {
        return prefix + "/check";
    }

    /**
     * 查询员工考勤列表
     */
    @RequiresPermissions("staff:check:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StaffCheck staffCheck)
    {
        startPage();
        List<StaffCheck> list = staffCheckService.selectStaffCheckList(staffCheck);
        return getDataTable(list);
    }

    /**
     * 导出员工考勤列表
     */
    @RequiresPermissions("staff:check:export")
    @Log(title = "员工考勤", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StaffCheck staffCheck)
    {
        List<StaffCheck> list = staffCheckService.selectStaffCheckList(staffCheck);
        ExcelUtil<StaffCheck> util = new ExcelUtil<StaffCheck>(StaffCheck.class);
        return util.exportExcel(list, "check");
    }

    /**
     * 新增员工考勤
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存员工考勤
     */
    @RequiresPermissions("staff:check:add")
    @Log(title = "员工考勤", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StaffCheck staffCheck)
    {
        return toAjax(staffCheckService.insertStaffCheck(staffCheck));
    }

    /**
     * 修改员工考勤
     */
    @GetMapping("/edit/{stfId}")
    public String edit(@PathVariable("stfId") String stfId, ModelMap mmap)
    {
        StaffCheck staffCheck = staffCheckService.selectStaffCheckById(Long.valueOf(stfId));
        mmap.put("staffCheck", staffCheck);
        return prefix + "/edit";
    }

    /**
     * 修改保存员工考勤
     */
    @RequiresPermissions("staff:check:edit")
    @Log(title = "员工考勤", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StaffCheck staffCheck)
    {
        return toAjax(staffCheckService.updateStaffCheck(staffCheck));
    }

    /**
     * 删除员工考勤
     */
    @RequiresPermissions("staff:check:remove")
    @Log(title = "员工考勤", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(staffCheckService.deleteStaffCheckByIds(ids));
    }
}
